import QtQuick 1.0
import com.nokia.symbian 1.0
import "../js/Constants.js" as Constants

Rectangle {
    id: rectangle1
    width: 360
    height: 578
    color: "#e6e6e6"
    border.color: "#000000"

    property string continuance_value_text: ""

    Flickable{
        id: toolbarFlickable
        flickableDirection: Flickable.VerticalFlick
        height: parent.height
        width: parent.width
        clip: true
        contentWidth: parent.width
        contentHeight: parent.height
        Text {
            id: text1
            width: 72
            height: 14
            text: qsTr("Settings")
            anchors.left: parent.left
            anchors.leftMargin: 21
            anchors.top: parent.top
            anchors.topMargin: 13
            font.pixelSize: 12
        }

        Text {
            id: text2
            y: 52
            width: 53
            height: 14
            text: qsTr("Continuance: ") + continuance_value_text
            anchors.left: parent.left
            anchors.leftMargin: 21
            font.pixelSize: 12
        }

        Slider {
            id: continuance_slider
            y: 101
            height: 62
            anchors.right: parent.right
            anchors.rightMargin: 26
            anchors.left: parent.left
            anchors.leftMargin: 21
            orientation: 1
            stepSize: 0.25
            onValueChanged: valueIndicatorText = continuance_value_text = calculateContinuance()
            valueIndicatorVisible: true
        }

        Text {
            id: text3
            y: 78
            width: 38
            height: 14
            text: qsTr("1 day")
            anchors.left: parent.left
            anchors.leftMargin: 21
            font.pixelSize: 12
        }

        Text {
            id: text4
            text: qsTr("1 month")
            anchors.left: parent.left
            anchors.leftMargin: 287
            anchors.top: parent.top
            anchors.topMargin: 78
            font.pixelSize: 12
        }

        CheckBox {
            id: checkbox2
            width: 314
            height: 40
            text: "Lactose free"
            anchors.top: checkbox1.bottom
            anchors.topMargin: 10
            anchors.left: parent.left
            anchors.leftMargin: 20
            textColor: "black"
        }

        CheckBox {
            id: checkbox3
            width: 314
            height: 40
            text: "Vegetable diet"
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.top: continuance_slider.bottom
            anchors.topMargin: 10
            textColor: "black"
        }

        CheckBox {
            id: checkbox1
            width: 314
            height: 40
            text: "Gluten free"
            anchors.top: checkbox3.bottom
            anchors.topMargin: 10
            anchors.leftMargin: 20
            anchors.left: parent.left
            textColor: "black"
        }

        Text {
            id: text5
            width: 65
            height: 14
            text: qsTr("Meet")
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.top: checkbox2.bottom
            anchors.topMargin: 20
            font.pixelSize: 12
        }

        Slider {
            id: meet_slider
            anchors.top: text5.bottom
            anchors.topMargin: 10
            anchors.left: parent.left
            anchors.leftMargin: 20
            orientation: 1
            value: 0.5
            onValueChanged: {
                calculateRations(Constants.MEET_RATIO);
            }
        }

        Text {
            id: text6
            x: -1
            y: -1
            width: 65
            height: 14
            text: qsTr("Fish")
            font.pixelSize: 12
            anchors.top: meet_slider.bottom
            anchors.topMargin: 10
            anchors.leftMargin: 20
            anchors.left: parent.left
        }

        Slider {
            id: fish_slider
            x: -1
            y: -1
            orientation: 1
            anchors.top: text6.bottom
            anchors.topMargin: 10
            anchors.leftMargin: 20
            anchors.left: parent.left
            value: 0.5
            onValueChanged: {
                calculateRations(Constants.FISH_RATIO);
            }
        }

        Button{
            id: generateButton
            anchors.top: fish_slider.bottom
            anchors.topMargin: 10
            anchors.horizontalCenter: parent.horizontalCenter
            text: qsTr("Generate menu")
            width: 200
        }
    }

    function calculateRations(itemChanged){
        switch(itemChanged)
        {
        case Constants.MEET_RATIO:
            fish_slider.value = 1 - meet_slider.value;
            break;
        case Constants.FISH_RATIO:
            meet_slider.value = 1 - fish_slider.value;
            break;
        case 3:
            break;
        default:
            break;
        }
    }

    function calculateContinuance(){
        var tempValue = continuance_slider.value * 100;
        var retVal = "";
        switch(tempValue)
        {
        case 0:
            retVal = "1 " + qsTr("day")
            break;
        case 25:
            retVal = "1 " + qsTr("week")
            break;
        case 50:
            retVal = "2 " + qsTr("weeks")
            break;
        case 75:
            retVal = "3 " + qsTr("weeks")
            break;
        case 100:
            retVal = "1 " + qsTr("month")
            break;
        }
        return retVal;
    }

    Behavior on width { PropertyAnimation { easing.type: Easing.InOutBack; duration: 1000 } }
    Behavior on opacity { NumberAnimation { duration: 1000 } }
    Behavior on visible { NumberAnimation { duration: 1000 } }
}
